package misp_backend.service;

import misp_backend.domain.CategorySalesVo;
import misp_backend.domain.MonthlySalesVo;
import misp_backend.mapper.StatisticsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Date;
import java.util.List;

@Service
public class StatisticsService {
    @Autowired
    private StatisticsMapper statisticsMapper;

    public List<CategorySalesVo> getCategorySales(LocalDate start, LocalDate end) {
        // 转换时区与数据库一致
        Date startDate = (Date) Date.from(start.atStartOfDay(ZoneId.systemDefault()).toInstant());
        Date endDate = (Date) Date.from(end.atTime(23, 59, 59).atZone(ZoneId.systemDefault()).toInstant());
        return statisticsMapper.selectCategorySales(startDate, endDate);
    }

    public List<MonthlySalesVo> getMonthlySales(Integer year) {
        return statisticsMapper.selectMonthlySales(year);
    }

}
